<template>
	<view>
		<!-- 分享上传 分享记录 -->
		<cus-navbar navbar :title="$t('index40')" ref="navbar" :rightText="$t('index49')" url="/pages/mine/uploadLog"></cus-navbar>
		<view class="main-padding">
			<view class="gap-30"></view>
			<!-- 分享平台 -->
			<view class="size-28 mb-20">{{$t('index50')}}</view>
			<!-- 请输入分享平台名称 -->
			<input type="text" v-model="name" :placeholder="$t('index51')" placeholder-class="color-71 size-26" class="upload-inp" />
			<!-- 分享有效链接 -->
			<view class="size-28 mb-20 mt-30">{{$t('index52')}}</view>
			<!-- 请输入分享有效链接 -->
			<input type="text" v-model="link" :placeholder="$t('index53')" placeholder-class="color-71 size-26" class="upload-inp" />
			<!-- 分享截图 -->
			<view class="size-28 mb-20 mt-30">{{$t('index54')}}</view>
			<view class="upload-box text-center">
				<image :src="url||'/static/imgs/15.png'" class="upload-img" mode="aspectFill" @click="upload"></image>
				<!-- 点击上传分享截图 -->
				<view class="color-71 size-24 mt-20">{{$t('index55')}}</view>
			</view>
		</view>
		<!-- 提交 -->
		<button class="upload-btn" @click="submit">{{$t('index56')}}</button>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				url:'',
				name:'',
				link:''
			}
		},
		onLoad(){},
		methods:{
			upload(){
				uni.chooseImage({
					count: 1,
					success: chooseImageRes=> {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.$api.upload('/data/api.data/upload', tempFilePaths[0]).then(res=>{
							this.url = res.url
						})
					}
				});
			},
			submit(){
				if(!this.name){
					uni.showToast({
						title:this.$t('index51'),// 请输入分享平台名称
						icon:"none"
					})
					return
				}
				if(!this.link){
					uni.showToast({
						title:this.$t('index53'),// 请输入分享有效链接
						icon:"none"
					})
					return
				}
				if(!this.url){
					uni.showToast({
						title:this.$t('index57'),// 请上传分享截图
						icon:"none"
					})
					return
				}
				this.$api.post('/data/api.auth.invest/sharePlatform',{
					platform_name: this.name,
					platform_url: this.link,
					platform_img: this.url
				}).then(res=>{
					uni.showToast({
						title:this.$t('index58')// 提交成功
					})
					setTimeout(()=>{
						this.$refs.navbar.navBack()
					},1200)
				})
			}
		}
	}
</script>

<style lang="scss">
.upload-inp{
	height: 88rpx;
	border-radius: 20rpx;
	padding: 0 30rpx;
	background-color: #1D1E25;
	width: 100%;
}
.upload-box{
	width: 310rpx;
	padding: 30rpx 0;
	background-color: #1D1E25;
	border-radius: 20rpx;
	.upload-img{
		width: 250rpx;
		height: 250rpx;
		border-radius: 10rpx;
	}
}
.upload-btn{
	width: 690rpx;
	height: 88rpx;
	border-radius: 20rpx;
	font-size: 28rpx;
	position: fixed;
	bottom: 74rpx;
	left: 30rpx;
}
</style>